﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CefSharp.WinForms;
using Newtonsoft.Json;
using SmartForm.Common;
using SmartlForm.Api;
using SmartlForm.Model;

namespace SmartlForm.NetJs
{
    public partial class BowContainer
    {


        public static Account account;

        /// <summary>
        /// 登陆
        /// </summary>
        /// <param name="mobile"></param>
        /// <param name="password"></param>
        /// <param name="autoLogin"></param>
        /// <returns></returns>
        public Result login(string mobile, string password, bool autoLogin)
        {
            var api = ApiHelper.Login(mobile, password);
            if (api.ret == 200)
            {
                //获取登录信息
                string token = api.data.token;
                api = ApiHelper.GetLoginInfo(token);
                if (api.ret == 200)
                {
                    account = JsonConvert.DeserializeObject<Account>(JsonConvert.SerializeObject(api.data));
                }
                startSmartCrawler();
                return ResultHelper.Success();
            }
            else
            {
                return ResultHelper.Error(api.msg);
            }
        }

        /// <summary>
        /// 获取登录信息
        /// </summary>
        /// <returns></returns>
        public Result getLoginAccount()
        {
            if (account != null)
            {
                return ResultHelper.Success("获取成功", JsonConvert.SerializeObject(account));
            }
            else
            {
                return ResultHelper.Code(Status.AUTH_FAIL, "未登录", null);
            }
        }

    }
}
